<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8"/>
  <title>Number</title>
  <link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
  <script src="https://cdn.jsdelivr.net/npm/mathjs@5.3.1/dist/math.min.js" class="external_mathjs"></script>
  <script src="../../dist/jsoneditor.js"></script>
</head>
<body>

<h1>Test</h1>
<label for="value">value</label>
<textarea class="value" id="value" cols="30" rows="10"></textarea>
<button class='get-value'>Get Value</button>
<button class='set-value'>Set Value</button>
<div class='json-editor-container'></div>

<script>
  var jsonEditorContainer = document.querySelector('.json-editor-container');
  var value = document.querySelector('.value');

  var schema = {
    "type": "object",
    "title": "range",
    "properties": {
      "number": {
        "title": "number",
        "type": "number",
        "default": 5.75,
        "minimum": 1,
        "maximum": 10
      },
      "number_number": {
        "title": "number number",
        "type": "number",
        "format": "number",
        "default": 5.75,
        "minimum": 1,
        "maximum": 10,
        "step": 0.25
      },
      "number_range": {
        "title": "number range",
        "type": "number",
        "format": "range",
        "default": 5.75,
        "minimum": 1,
        "maximum": 10,
        "step": 0.25
      },
      "stepper_number": {
        "title": "stepper number",
        "format": "stepper",
        "type": "number",
        "minimum": 1,
        "maximum": 10,
        "step": 0.25
      },
      "stepper_integer": {
        "title": "stepper integer",
        "format": "stepper",
        "type": "integer",
        "minimum": 1,
        "maximum": 10,
        "step": 0.25
      },
      "stepper_number_default": {
        "title": "stepper number",
        "format": "stepper",
        "type": "number",
        "minimum": 1,
        "maximum": 10,
        "step": 0.25,
        "default": 5
      },
      "stepper_integer_default": {
        "title": "stepper integer",
        "format": "stepper",
        "type": "integer",
        "minimum": 1,
        "maximum": 10,
        "step": 1,
        "default": 5
      }
    }
  };

  var editor = new JSONEditor(jsonEditorContainer, {
    schema: schema,
    theme: 'bootstrap4',
    use_default_values: false,
    show_errors: 'always'
  });

  document.querySelector('.get-value').addEventListener('click', function () {
    value.value = JSON.stringify(editor.getValue());
    console.log(editor.getValue());
  });

  document.querySelector('.set-value').addEventListener('click', function () {
    editor.setValue({number_range: 2})
  });

</script>

</body>
</html>
